#include<bits/stdc++.h>
using namespace std;
int T,n,p;
long long a[200005],ans,sum;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    for (int t=1;t<=T;t++){
        scanf("%d",&n);
        for (int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
        }
        ans=0LL;
        for (long long i=0LL;i<(1LL<<n);i++){
            sum=0LL;
            for (int j=2;j<=n;j++){
                p=-1;
                for (int k=j-1;k>=1;k--){
                    if (!(((i>>j-1)&1) ^ ((i>>k-1)&1)) && a[j] == a[k]){
                        p=k;break;
                    }
                }
                if (p != -1){
                    sum+=a[j];
                    //printf("%d:%d ",j,p);
                }
            }
            ans=max(ans,sum);
        }
        printf("%lld\n",ans);
    }
    return 0;
}
